package com.light.netty.client.coder;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

public class UdpMessageDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
        // 根据协议解析消息（示例：假设消息长度为4字节）
        if (in.readableBytes() < 4) return;
        int length = in.readInt();
        ByteBuf message = in.readBytes(length);
        out.add(message);
    }
}
